package com.fancy.middleware.common.utils;

import org.springframework.context.ApplicationContext;

import java.util.Map;

public class ContextUtils {

    private static ApplicationContext ctx;
    public static void setApplicationContext(ApplicationContext applicationContext) {
        ctx = applicationContext;
    }

    public static Object getBeanByName(String name){
        return ctx.getBean(name);
    }

    public static <T> Map<String, T> getBeansByType(Class<T> requiredType) {
        return ctx.getBeansOfType(requiredType);
    }

    public static <T> T getBeanByType(Class<T> requiredType) {
        return ctx.getBean(requiredType);
    }



}
